package com.example.entitydemo.controller;

import com.example.entitydemo.base.response.JsonResult;
import com.example.entitydemo.pojo.entity.User;
import com.example.entitydemo.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;


    @PostMapping("/save")
    public JsonResult save(@RequestBody User user) {
       log.debug("user={}",user);
        userService.save(user);
        return JsonResult.ok();
    }

    @PostMapping("/update")
    public JsonResult update(@RequestBody User user) {
        log.debug("user={}",user);
        userService.update(user);
        return JsonResult.ok();
    }

    @PostMapping("/deleteById")
    public JsonResult deleteById(@RequestBody User user) {
        log.debug("user={}",user);
        userService.deleteById(user);
        return JsonResult.ok();
    }

    @GetMapping("/select")
    public JsonResult select(User user) {
        log.debug("user={}",user);
        List<User> select = userService.select(user);
        return JsonResult.ok(select);
    }
}
